import { fetchEventSource } from "@microsoft/fetch-event-source";
import { config } from "@/config/axios/config";
import request from "@/config/axios"; // AI 思维导图 VO
import { getUserToken, removeUserToken } from "@/store/session";
export const AiMindMapApi = {
  generateMindMap: ({ data, onClose, onMessage, onError, ctrl }) => {
    const token = getUserToken();
    return fetchEventSource(`${config.base_url}/ai/mind-map/generate-stream`, {
      method: "post",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${token}`,
      },
      openWhenHidden: true,
      body: JSON.stringify(data),
      onmessage: onMessage,
      onerror: onError,
      onclose: onClose,
      signal: ctrl.signal,
    });
  },

  // 二次修改重新生成保存
  regenerateMapPage: async (data) => {
    return await request.post({ url: `/ai/mind-map/regenerate`, data });
  },
  // 查询思维导图分页
  getMindMapPage: async (params) => {
    return await request.get({ url: `/ai/mind-map/my-page`, params });
  },
  // 删除思维导图
  deleteMindMap: async (id) => {
    return await request.delete({ url: `/ai/mind-map/delete-my?id=` + id });
  },
};
